package com.weirong.smartvault.backservice.service;

import com.weirong.smartvault.dao.ForeignCurrencyDenominationRepository;
import com.weirong.smartvault.entity.ForeignCurrencyDenomination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ForeignCurrencyDenominationService {

    @Autowired
    private ForeignCurrencyDenominationRepository foreignCurrencyDenominationRepository;

    public List<ForeignCurrencyDenomination> getForeignCurrencyDenominationByTypeCode(String typeCode)
    {
        return this.foreignCurrencyDenominationRepository.getForeignCurrencyDenominationByTypeCode(typeCode);
    }

    public Optional<ForeignCurrencyDenomination> getForeignCurrencyDenominationByTypeCodeAndValue(String typeCode, int value)
        {
        List<ForeignCurrencyDenomination> foreignCurrencyDenominations = this.foreignCurrencyDenominationRepository.getForeignCurrencyDenominationByTypeCodeAndValue(typeCode, value);
        if (foreignCurrencyDenominations == null || foreignCurrencyDenominations.isEmpty()) return Optional.empty();
        return Optional.of(foreignCurrencyDenominations.get(0));
    }
}
